<?php

class AskController extends Controller {
	private $DB;
	public function __Init(){
		$this->DB = new AskModel;
	}
	public function index(){
		if(ISPOST){
			if($this->DB->addAsk()){
				echo "<script>alert('提问成功');location.href='?m=Index&a=index';</script>";
				return true;
			}else{
				echo "<script>alert('".$this->DB->error."');location.href='?m=Index&c=Ask&a=index';</script>";
				return false;
			}
		}else{
			// 实例化栏目类
			$CatInfo = new CategoryController;
			// 获取顶级分类
			$BigCat = $CatInfo->BigCategory();
			// 分配顶级分类信息
			$this->assign('BigCategory',$BigCat);
			// 分配问题列表
			$this->assign('ask',$CatInfo->AskList());
			// 分配用户信息
			if(!empty($_SESSION['id'])){
				$this->assign('userInfo',$this->DB->getUser());
			}
			$this->display('ask.html');
		}
	}
	public function AskCat(){
		$_POST['cid']=isset($_POST['cid'])?$_POST['cid']:1;
		$Cat = new CategoryController;
		$MiniCat = $Cat->MinCategory($_POST['cid']);
		echo json_encode($MiniCat);
	}

	public function allAsk(){
		$AskInfo = $this->DB->AllAsk();
		$this->assign('AskInfo',$AskInfo['AskList']);
		$this->assign('PageList',$AskInfo['Pages']);
		$this->assign('count',$AskInfo['count']);
		// p($AskInfo['AskList']);
		$this->display('allAsk.html');
	}

	public function whiteAsk(){
		// 待解决问题相关信息
		$AskList = $this->DB->WhiteAsk();
		// 分页信息
		$this->assign('Pages',$AskList['Pages']);
		// 待解决问题列表
		$this->assign('AskList',$AskList['AskList']);
		// 待解决问题数量
		$this->assign('count',$AskList['count']);
		$this->display('whiteAsk.html');
	}

	public function settleAsk(){
		// 已解决问题相关信息
		$AskList = $this->DB->SettleAsk();
		// 分页信息
		$this->assign('Pages',$AskList['Pages']);
		// 已解决问题列表
		$this->assign('AskList',$AskList['AskList']);
		// 已解决问题数量
		$this->assign('count',$AskList['count']);
		$this->display('settleAsk.html');
	}

	public function noAnswerAsk(){
		// 没有回答的问题相关信息
		$AskList = $this->DB->NoAnswerAsk();
		// 分页信息
		$this->assign('Pages',$AskList['Pages']);
		// 没有回答的问题列表
		$this->assign('AskList',$AskList['AskList']);
		// 没有回答的问题数量
		$this->assign('count',$AskList['count']);
		$this->display('answerAsk.html');
	}

	public function count(){
		return $this->DB->count();
	}

	public function getList(){
		$Field = $this->DB->getList();
		if(isset($_GET['cid'])){
			// 获取跟下面但个记录的分类相同顶级分类的记录
			$this->assign('Field',$Field['Field']);
			// 顶级分类
			$this->assign('top',$Field['top']);
			// 获取当前被点击的那条分类相关的记录
			$this->assign('Find',$Field['Find']);
			// 获取跟当前分类相关的问题列表
			$this->assign('Ask',$Field['Ask']);
		}else{
			// 获取所有的顶级分类
			$this->assign('Field',$Field['Field']);
			// 获取跟当前分类相关的问题列表
			$this->assign('Ask',$Field['Ask']);
		}
		$this->display('list.html');
	}

}


?>